package com.company.project.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.entity.TZjhmglEntity;
import com.company.project.service.HttpSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.company.project.mapper.TMiddlenumMapper;
import com.company.project.entity.TMiddlenumEntity;
import com.company.project.service.TMiddlenumService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Service("tMiddlenumService")
public class TMiddlenumServiceImpl extends ServiceImpl<TMiddlenumMapper, TMiddlenumEntity> implements TMiddlenumService {
    @Resource
    private TMiddlenumMapper tMiddlenumMapper;
    @Autowired
    private HttpSessionService httpSessionService;
    @Override
    public List<TMiddlenumEntity> getZjhByTseatId(String tseatsid) {
        //获取当前操作人
        String userId = httpSessionService.getCurrentUserId();
        List<TMiddlenumEntity> tZjhmglEntities = tMiddlenumMapper.selectList(Wrappers.<TMiddlenumEntity>lambdaQuery()
                .eq(TMiddlenumEntity::getCjr, userId)
                .orderByDesc(TMiddlenumEntity::getAddtime));
        return tZjhmglEntities;
    }

    @Transactional
    @Override
    public void updateEntity(TMiddlenumEntity tMiddlenum) {
        tMiddlenum.setMiddlenum(tMiddlenum.getMiddlenumInput());
        //获取当前操作人
        String userId = httpSessionService.getCurrentUserId();
        Long integer = tMiddlenumMapper.selectCount(Wrappers.<TMiddlenumEntity>lambdaQuery()
                        .eq(TMiddlenumEntity::getMiddlenum,tMiddlenum.getMiddlenum())
                .eq(TMiddlenumEntity::getCjr, userId));
//        if (integer>0) {
//            throw new RuntimeException("");
//        }
        this.updateById(tMiddlenum);
    }

}